package com.kanshu.ksgb.fastread.doudou.module.book.adapter;

import android.content.Context;
import android.util.Log;
import android.widget.ImageView;

import com.kanshu.ksgb.fastread.doudou.R;
import com.kanshu.ksgb.fastread.doudou.base.baseadapter.abslistview.CommonAdapter;
import com.kanshu.ksgb.fastread.doudou.base.baseadapter.abslistview.ViewHolder;
import com.kanshu.ksgb.fastread.doudou.module.book.bean.ReadTheme;
import com.kanshu.ksgb.fastread.doudou.module.reader.utils.ThemeManager;

import java.util.List;


/**
 * 阅读器主题色适配器
 * Created by wcy on 2017\7\4 0004.
 */

public class ReadThemeAdapter extends CommonAdapter<ReadTheme>{
    private int selected = 0;
    public ReadThemeAdapter(Context context, int layoutId, List<ReadTheme> datas) {
        super(context, layoutId, datas);
    }

    public void setSelected(int selected) {
        this.selected = selected;
        notifyDataSetChanged();
    }
    public int getSelected() {
        return selected;
    }
    @Override
    protected void convert(ViewHolder holder, ReadTheme readTheme, int position) {
        if (readTheme != null) {
            ImageView view = holder.getView(R.id.ivThemeBg);
            ReadTheme theme = mDatas.get(selected);
            boolean flg = theme.theme == readTheme.theme;
//            view.setScaleType(ImageView.ScaleType.CENTER_CROP);
            switch (readTheme.theme) {
                case ThemeManager.NORMAL:
                    view.setImageResource(flg ? R.mipmap.ic_theme_white_bg:R.mipmap.ic_theme_white_p_bg);
                    break;
                case ThemeManager.YELLOW:
                    view.setImageResource(flg ? R.mipmap.ic_theme_yellow_bg:R.mipmap.ic_theme_yellow_p_bg);
                    break;
                case ThemeManager.GREEN:
                    view.setImageResource(flg ? R.mipmap.ic_theme_green_bg:R.mipmap.ic_theme_green_p_bg);
                    break;
                case ThemeManager.LEATHER:
                    view.setImageResource(flg ? R.mipmap.ic_theme_leather_bg:R.mipmap.ic_theme_leather_p_bg);
                    break;
                case ThemeManager.GRAY:
                    view.setImageResource(flg ? R.mipmap.ic_theme_gray_bg:R.mipmap.ic_theme_gray_p_bg);
                    break;
                case ThemeManager.NIGHT:
                    view.setImageResource(flg ? R.mipmap.ic_theme_black_bg:R.mipmap.ic_theme_black_p_bg);
                    Log.d("wcy", "night");
                    break;
                default:
                    break;
            }
        }
    }
}
